﻿#region 命名空间

using System.Data.Entity;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Sharp.Application.CMS;
using Sharp.Domain.CMSBoundedContext;
using Sharp.Domain.CMSBoundedContext.AritcleModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.AritcleModule.GatherEngine;
using Sharp.Domain.CMSBoundedContext.MemberModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.OperationModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.VIUModule.Aggregates;
using Sharp.Domain.CMSBoundedContext.VIUModule.Services;
using Sharp.Domain.Repositories;
using Sharp.Domain.Repository.EF;
using Sharp.Infrastructure;
using Sharp.Infrastructure.Crosscutting;
using Sharp.Infrastructure.Interfaces;
using Sharp.Infrastructure.IoC;
using Sharp.ServiceContracts.CMS;

#endregion

namespace Sharp.Services.CMS
{

    /// <summary>
    ///     DI container accesor
    /// </summary>
    public static class Container
    {
        

        public static void ConfigureContainer()
        {
            ServiceLocator.RegisterType<DbContext, Entities>();
            ServiceLocator.RegisterType<IRepositoryContext, EntityFrameworkRepositoryContext>(
                new WcfPerRequestLifetimeManager());

            #region repositories 

            ServiceLocator.RegisterType<IVIUCategoryRepository, VIUCategoryRepository>();
            ServiceLocator.RegisterType<ICommentRepository, CommentRepository>();
            ServiceLocator.RegisterType<IDiggRepository, DiggRepository>();
            ServiceLocator.RegisterType<IDiggDiaryRepository, DiggDiaryRepository>();
            ServiceLocator.RegisterType<IMultiMediaRepository, MultiMediaRepository>();
            ServiceLocator.RegisterType<ITagRepository, TagRepository>();
            ServiceLocator.RegisterType<IVIURepository, VIURepository>();
            ServiceLocator.RegisterType<IVIUCategoryRepository, VIUCategoryRepository>();
            ServiceLocator.RegisterType<IFieldRepository, FieldRepository>();
            ServiceLocator.RegisterType<IApproveHistoryRepository, ApproveHistoryRepository>();
            ServiceLocator.RegisterType<IArticleRepository, ArticleRepository>();
            ServiceLocator.RegisterType<ICommentRepository, CommentRepository>();
            ServiceLocator.RegisterType<IFavoriteRepository, FavoriteRepository>();
            ServiceLocator.RegisterType<IIPBlackListRepository, IPBlackListRepository>();
            ServiceLocator.RegisterType<INoiseWordRepository, NoiseWordRepository>();
            ServiceLocator.RegisterType<IOAuthRepository, OAuthRepository>();
            ServiceLocator.RegisterType<IColumnRepository, ColumnRepository>();
            ServiceLocator.RegisterType<ISpecialRepository, SpecialRepository>();
            ServiceLocator.RegisterType<IGatherRepository, GatherRepository>();
            ServiceLocator.RegisterType<IGatherHistoryRepository, GatherHistoryRepository>();
            ServiceLocator.RegisterType<IGatherUrlCacheRepository, GatherUrlCacheRepository>();

            #endregion

            #region  Domain Service


            ServiceLocator.RegisterType<IVIUService, VIUService>();
            ServiceLocator.RegisterType<IGatherContentPage, GatherContentPage>();
            ServiceLocator.RegisterType<IGatherEngineMain, GatherEngineMain>();

            #endregion

            #region 实现



            ServiceLocator.RegisterType(typeof (ICMSService), typeof (CMSServiceImpl),
                new Interceptor<TransparentProxyInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>(),
                new InterceptionBehavior(new ExceptionLoggingBehavior())
                );
            ServiceLocator.RegisterType(typeof (IMemberService), typeof (MemberServiceImpl),
                new Interceptor<TransparentProxyInterceptor>(),
                new InterceptionBehavior<PolicyInjectionBehavior>(),
                new InterceptionBehavior(new ExceptionLoggingBehavior())
                );

            #endregion

            ServiceLocator.RegisterType<IBootstrapPlugin, Sharp.Application.CMS.Bootstraper>("A");
            ServiceLocator.RegisterType<IBootstrapPlugin, Sharp.Domain.CMSBoundedContext.Bootstraper>("B");
            
        }


        public static void ConfigureFactories()
        {
            //LogFactory.SetCurrent(new TraceSourceLogFactory());
            //EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
    }
}